package xyf.p04.tree;

import commons.TreeNode;

/**
 * ClassName: J054_KthNode
 * Description:
 * Author: xyf
 * Date: 9/8/22 6:13 PM
 * Version: 1.0
 **/
public class J054_KthNode
{
    int res = -1;

    int current = 0;

    public int kthLargest(TreeNode root, int k)
    {
        inOrder(root, k);
        return res;
    }

    private void inOrder(TreeNode root, int k)
    {
        if (root == null)
        {
            return;
        }

        inOrder(root.right, k);

        current += 1;
        if (current == k)
        {
            res = root.val;
            return;
        }
        inOrder(root.left, k);
    }
}